package cn.stylefeng.guns.sys.modular.system.quartz.task;

import cn.stylefeng.guns.sys.core.util.DateUtil;
import cn.stylefeng.guns.sys.modular.system.entity.BtyWx;
import cn.stylefeng.guns.sys.modular.system.service.BtyWxService;
import cn.stylefeng.guns.sys.modular.system.service.WeChatSendTempMsgService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

//作业不并发
@DisallowConcurrentExecution
@Component
public class HelloWorldJob implements Job {
    @Resource
    private BtyWxService btyWxService;
    private Logger logger = LoggerFactory.getLogger(HelloWorldJob.class);
    @Resource
    private WeChatSendTempMsgService weChatSendTempMsgService;

    @Override
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
        logger.info("====推送更新内容开始====");
        //List<BtyWx>list=btyWxService.list(new QueryWrapper<BtyWx>().in("openid",new Object[]{"oM18PwW_aRtOaOH0F-YwsmMxT2sM","oM18PwQBM_f-4xlF7DKwnLQZ7XXc"}));
        List<BtyWx>list=btyWxService.list(new QueryWrapper<BtyWx>().in("openid",new Object[]{"oM18PwW_aRtOaOH0F-YwsmMxT2sM"}));
        //List<BtyWx> list=btyWxService.list(new QueryWrapper<BtyWx>().isNotNull("dept_id"));
        String[] openids;
        String data = "更新！1.工程条件保证金改为一次性 2.通讯录修改 3.石家庄万象城店定时更新每日销售额 4.工程添加不显示";
        String date= DateUtil.getNow();
        JSONObject tempObj = weChatSendTempMsgService.setTempParam("更新", data,date,"信息技术部", "半天妖管理系统", "信息技术部", data);
        if(ToolUtil.isNotEmpty(list)){
            for (int i = 0; i < list.size(); i++) {
                String openid=list.get(i).getOpenid();
                openids = new String[]{openid};
                weChatSendTempMsgService.sendMsgUpdateContent(openids, null, tempObj);
            }
            logger.info("====推送更新内容完成====");
        }
        System.out.println("推送更新内容任务执行, --执行成功!");
    }

}